﻿using System.Collections.Generic;
using System.Text.RegularExpressions;
using AllInOnePluginBL.Helpers;

namespace AllInOnePluginBL.FileHostingExtractors
{
    /// <summary>
    /// Summary description for SdarotOrgExtractor
    /// </summary>
    public class SdarotOrgExtractor : IFileHostingExtractor
    {
        //private const string BASE_URL = "http://www.sdarot.org";

        public List<string> GetMovieUrls(string content)
        {
            var movieUrls = new List<string>();

        

            return movieUrls;
        }

        public VideoResult ExtractMovieUrl(string movieUrl)
        {
            const string MoviePathFormat = "http://media.sdarot.org/media/videos/flv/{0}.flv";
            var matches = Regex.Matches(movieUrl, "http://www.sdarot.org/video/(.+?)/", RegexOptions.Singleline);
            var movie_id = matches[0].Groups[1].Value;
            var movie_name = movieUrl.Substring(movieUrl.LastIndexOf("/")+1);
            var moviePath = string.Format(MoviePathFormat, movie_id);
            return new VideoResult(moviePath, movie_name, true);

            //var cookieString = Utils.GetCookieString(BASE_URL);
            //var pageContent = Utils.GetPageWithCookieHeader(movieUrl, Encoding.UTF8, cookieString);
            //var video_link = Regex.Match(pageContent, "s1.addVariable.'file', '(.+?)'.;", RegexOptions.Singleline).Groups[1].Value;
            //var movieName = Path.GetFileName(movieUrl);
            //return new VideoResult(video_link, movieName, true);
        }

        public bool IsContainVideoLink(string content)
        {
            return content.Contains("sdarot.org");
        }
    }
}